package com.woniuxy.microsystemsarserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microsystemsarserver.bean.InvoiceBean;
import com.woniuxy.microsystemsarserver.bean.PageRequestBean;
import com.woniuxy.microsystemsarserver.mapper.InvoiceMapper;
import com.woniuxy.microsystemsarserver.service.IInvoiceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 发票记录管理业务层实现类
 * @author 杨灿
 */
@Service
@Transactional(readOnly = true)
public class InvoiceServiceImpl implements IInvoiceService {
    @Resource
    private InvoiceMapper invoiceMapper;

    @Override
    public PageInfo<InvoiceBean> findByPage(InvoiceBean invoiceBean, PageRequestBean pageRequestBean,Long userId) {
        return PageHelper.startPage(pageRequestBean.getPageNum(),pageRequestBean.getLimit()).
                doSelectPageInfo(()->invoiceMapper.findByPage(invoiceBean,pageRequestBean,userId));

    }

    @Override
    public List<InvoiceBean> findAll(Long userId) {
        return invoiceMapper.findAll(userId);
    }

    @Override
    public InvoiceBean findById(Long invoiceId) {

        return invoiceMapper.findById(invoiceId);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public int updateInvoice(InvoiceBean invoiceBean) {

        return invoiceMapper.updateInvoice(invoiceBean);
    }
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public int saveInvoice(InvoiceBean invoiceBean) {

        return invoiceMapper.saveInvoice(invoiceBean);
    }
}
